﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack )
        {
            LoadData();
        }
    }
    public void LoadData()
    {
        AlbumBUS albumBUS = new AlbumBUS();
        DataListAlbum.DataSource = albumBUS.GetListAlbum();
        DataListAlbum.DataBind();
    }
    protected void DataListAlbum_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if ( e.CommandName == "AddToCart" )
        {
            try
            {
                AlbumBUS albumBUS = new AlbumBUS();
                //lay ma album
                int iAlbumID = int.Parse(DataListAlbum.DataKeys[e.Item.ItemIndex].ToString());
                var albumCurrent = albumBUS.GetAlbumItemByAlbumID(iAlbumID);
                var shoppingCart = ShoppingCartDTO.GetShoppingCartCurrent(HttpContext.Current);
                bool bCheck_AddToCart = shoppingCart.AddToCart(albumCurrent);
                if (bCheck_AddToCart == true)
                {
                    Response.Redirect("~/ViewCart.aspx");
                }
            }
            catch ( Exception ex)
            {
                throw ex;
            }
        }
    }
}